#include "ConfigReader.h"

int _isInit;
xmlDocPtr doc;
//xmlParserCtxtPtr context;

enum ORETURNCODE initConfig(char *fileName)
{
	//context = xmlNewParserCtxt();

	if (_isInit == 0)
	{
		/* this initializes the library and check potential ABI mismatches
		* between the version it was compiled for and the actual shared
		* library used. */
		LIBXML_TEST_VERSION
		doc = xmlReadFile(fileName, NULL, 0);
		//doc = xmlCtxtReadFile(context, fileName, NULL, XML_PARSE_DTDVALID);
		if (doc == NULL)
		{
			writeLog(__func__,VSEVERE,LOGLEVEL,"Error opening Config file! (%s)",fileName);
			return OFILENOTFOUND;
		}
		/*else if (context->valid == 0)
		{
			writeLog(__func__,VSEVERE,LOGLEVEL,"Validation Error - %s",context->lastError.message);
			return OINVALIDXML;
		}*/
		else
		{
			_isInit = 1;
			
		}
	}
	return ONOERR;
}
enum ORETURNCODE deInitConfig()
{
	if (_isInit == 1)
	{
		//fclose(fConf);
		xmlFreeDoc(doc);
		xmlCleanupParser();
		//xmlFreeParserCtxt(context);
		return ONOERR;
	}
	else
	{
		writeLog(__func__,VERROR,LOGLEVEL,"Config file has not been init'ed!");
		return OCONFIGNOTINIT;
	}
}
